package br.com.petsis.captcha;

import java.awt.Color;

import org.jboss.seam.annotations.Name;
import org.jboss.seam.captcha.CaptchaImage;

import com.octo.captcha.component.image.backgroundgenerator.UniColorBackgroundGenerator;
import com.octo.captcha.component.image.fontgenerator.TwistedRandomFontGenerator;
import com.octo.captcha.component.image.textpaster.RandomTextPaster;
import com.octo.captcha.component.image.wordtoimage.ComposedWordToImage;
import com.octo.captcha.component.word.wordgenerator.RandomWordGenerator;
import com.octo.captcha.engine.image.gimpy.BasicGimpyEngine;
import com.octo.captcha.image.gimpy.GimpyFactory;
import com.octo.captcha.service.captchastore.FastHashMapCaptchaStore;
import com.octo.captcha.service.image.DefaultManageableImageCaptchaService;
import com.octo.captcha.service.image.ImageCaptchaService;

@Name("customCaptcha")
//@Scope(ScopeType.APPLICATION)
//@Install(precedence = Install.BUILT_IN)
//@BypassInterceptors
public class CustomCaptcha extends CaptchaImage{
	
	public ImageCaptchaService getService() {
	   	BasicGimpyEngine customCaptcha = new BasicGimpyEngine();
	      
		GimpyFactory factory = new GimpyFactory(
	            new RandomWordGenerator("23456789ABCDEFGHJLMNPQRSTUVWYZabcdefghjkmnpqrstuvwyz"), 
	            new ComposedWordToImage(
	            		new TwistedRandomFontGenerator(new Integer(15), new Integer(15)), 
	            		new UniColorBackgroundGenerator(new Integer(150), new Integer(30)), 
	            		new RandomTextPaster(new Integer(6), new Integer(6), Color.BLACK))
	            );
	     
	      GimpyFactory[] factories = {factory};
	      customCaptcha.setFactories(factories);
	      
	      return new DefaultManageableImageCaptchaService(
	                   new FastHashMapCaptchaStore(),
	                   customCaptcha,
	                   180,
	                   120000,
	                   75000);      
	   }
	
}
